/**
 * @author 黄波
 * 创建日期：2011Sep 27, 2011
 * TODO// N/A
 */
package com.platform.course.action;

import java.util.ArrayList;
import java.util.List;

import com.platform.bean.PageBean;
import com.platform.common.bo.CommonBo;
import com.platform.course.bean.CourseBean;
import com.platform.course.bo.CourseBo;
import com.platform.pojo.CourseInfo;
import com.platform.pojo.SchoolProperty;
import com.platform.user.bo.UserBo;

/**
 * 分页加载课程信息
 */
public class LoadCourseListAction extends CourseSupport {

	private String nodeText;
	private PageBean pageBean;
	private List<CourseBean> items;
	
	public String getNodeText() {
		return nodeText;
	}
	public void setNodeText(String nodeText) {
		this.nodeText = nodeText;
	}
	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	
	public List<CourseBean> getItems() {
		return items;
	}
	public void setItems(List<CourseBean> items) {
		this.items = items;
	}
	@Override
	public String execute() throws Exception {

		CourseBo bo = CourseBo.getInstance();
		Object[] objs = bo.getInfos(pageBean);
		pageBean = (PageBean)objs[0];
		List<CourseInfo> infos = (List)objs[1];
		items = new ArrayList<CourseBean>();
		//用户bo
		UserBo userBo = UserBo.getInstance();
		//公共属性
		CommonBo commonBo = CommonBo.getInstance();
		
		for(CourseInfo item : infos) {
			CourseBean bean = new CourseBean();
			//课程实体
			bean.setItem(item);
			//任课老师
			bean.setTeacher(userBo.getUser(item.getUserId().toString()).getRealName());
			//班级名称
			SchoolProperty sp = commonBo.getSchoolProperty(item.getClassId().toString());
			if(sp != null) {
				bean.setClassName(sp.getName());
				bean.setClassNum(sp.getClassNum().toString());
			}
			items.add(bean);
		}
		if(nodeText != null) {
			nodeText = new String(nodeText.getBytes("iso-8859-1"), "utf-8");
		}
		return SUCCESS;
	}
	
}
